from dbentries.userinfo import *
from google.appengine.api import users
from google.appengine.ext import db

class UserControl:
    def add_user(cls, user, phoneno, category, userdescription):
        user_info = UserInfo(acount=users.get_current_user(),
                             phone=phoneno,
                             category=category,
                             description=userdescription)
        return user_info.put()
    
    def get_end_user(cls,userinfo):
        query = db.GqlQuery("SELECT * FROM UserInfo WHERE acount = :1", userinfo)
        return query.get()

    def get_relationship(user):
        userinfo = get_user(user)
        if(userinfo.count > 0):
            query = db.GqlQuery("SELECT * FROM Relationship WHERE phone = :1", userinfo.phone)
            return query
        else:
            return None

class MoneyControl:
    def add_item(cls, user_info, in_or_out, cost, category, description):
        item = MoneyItem(owner = user_info, 
                         in_or_out = in_or_out,
                         cost = cost,
                         category = category,
                         description = description)
        item.put()
    
    def get_item_by_user(cls,user_info):
        query = db.GqlQuery("SELECT * FROM MoneyItem WHERE owner = :1", user_info)
        return query.fetch(10)
